package com.braveman.im.ui.activity.message;

import android.content.Intent;
import android.view.View;

import com.braveman.im.R;
import com.braveman.im.bean.TopGroupSettingBean;
import com.braveman.im.manager.ApiManager;
import com.braveman.im.ui.weiget.ButtonItem;
import com.braveman.im.utils.UtilsStyle;
import com.ht.baselibs.retrofit.NetCallBack;
import com.ht.baselibs.ui.base.BaseActivity;
import com.ht.baselibs.utils.ActivityUtils;
import com.ht.baselibs.utils.UIUtils;
import com.vondear.rxtools.RxBarTool;

import java.util.ArrayList;

import retrofit2.Call;
import retrofit2.Response;

class SettingGroupPostionActivity extends BaseActivity {
    private ButtonItem mTop0;
    private ButtonItem mTop1;
    private ButtonItem mTop2;
    private ButtonItem mTop3;
    private ButtonItem mTop4;
    private ButtonItem mTop5;
    private ButtonItem mTop6;
    private ButtonItem mTop7;
    private ButtonItem mTop8;
    private ButtonItem mTop9;
    private String groupId;
    private int stickIndex;


    @Override
    protected void initTitleBar() {
        mTitleBarView.setTitleText("设置置顶群").setLeftBtnIcon(R.mipmap.back_black).setOnLeftBtnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ActivityUtils.finishActivity(SettingGroupPostionActivity.this);
            }
        });
    }

    @Override
    protected boolean isStaticPage() {
        return true;
    }

    @Override
    protected void initIntentData(Intent callIntent) {
        groupId = callIntent.getStringExtra("groupId");
    }

    @Override
    protected int initContentView() {
        UtilsStyle.setStatusBarMode(this, true);
        RxBarTool.FlymeSetStatusBarLightMode(getWindow(), true);
        RxBarTool.MIUISetStatusBarLightMode(getWindow(), true);
        return R.layout.activity_setting_group_positon;
    }

    @Override
    protected void initChildView() {
        mTop0 = (ButtonItem) findViewById(R.id.top0);
        mTop1 = (ButtonItem) findViewById(R.id.top1);
        mTop2 = (ButtonItem) findViewById(R.id.top2);
        mTop3 = (ButtonItem) findViewById(R.id.top3);
        mTop4 = (ButtonItem) findViewById(R.id.top4);
        mTop5 = (ButtonItem) findViewById(R.id.top5);
        mTop6 = (ButtonItem) findViewById(R.id.top6);
        mTop7 = (ButtonItem) findViewById(R.id.top7);
        mTop8 = (ButtonItem) findViewById(R.id.top8);
        mTop9 = (ButtonItem) findViewById(R.id.top9);
        reSet();
    }

    @Override
    protected void initChildData() {

    }

    @Override
    protected void setChildViewListener() {
        mTop0.setOnClickListener(this);
        mTop1.setOnClickListener(this);
        mTop2.setOnClickListener(this);
        mTop3.setOnClickListener(this);
        mTop4.setOnClickListener(this);
        mTop5.setOnClickListener(this);
        mTop6.setOnClickListener(this);
        mTop7.setOnClickListener(this);
        mTop8.setOnClickListener(this);
        mTop9.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        super.onClick(v);
        reSet();
        switch (v.getId()) {
            case R.id.top0:
                stickIndex = 1;
                mTop0.setSelected(true);
                mTop0.iv_click.setVisibility(View.VISIBLE);
                break;
            case R.id.top1:
                stickIndex = 2;
                mTop1.setSelected(true);
                mTop1.iv_click.setVisibility(View.VISIBLE);
                break;
            case R.id.top2:
                stickIndex = 3;
                mTop2.setSelected(true);
                mTop2.iv_click.setVisibility(View.VISIBLE);
                break;
            case R.id.top3:
                stickIndex = 4;
                mTop3.setSelected(true);
                mTop3.iv_click.setVisibility(View.VISIBLE);
                break;
            case R.id.top4:
                stickIndex = 5;
                mTop4.setSelected(true);
                mTop4.iv_click.setVisibility(View.VISIBLE);
                break;
            case R.id.top5:
                stickIndex = 6;
                mTop5.setSelected(true);
                mTop5.iv_click.setVisibility(View.VISIBLE);
                break;
            case R.id.top6:
                stickIndex = 7;
                mTop6.setSelected(true);
                mTop6.iv_click.setVisibility(View.VISIBLE);
                break;
            case R.id.top7:
                stickIndex = 8;
                mTop7.setSelected(true);
                mTop7.iv_click.setVisibility(View.VISIBLE);
                break;
            case R.id.top8:
                stickIndex = 9;
                mTop8.setSelected(true);
                mTop8.iv_click.setVisibility(View.VISIBLE);
                break;
            case R.id.top9:
                stickIndex = 10;
                mTop9.setSelected(true);
                mTop9.iv_click.setVisibility(View.VISIBLE);
                break;

        }
        doNetWork();
    }

    private void doNetWork() {
        TopGroupSettingBean topGroupSettingBean = new TopGroupSettingBean();
        topGroupSettingBean.stickList = new ArrayList<>();
        TopGroupSettingBean.StickListBean stickListBean = new TopGroupSettingBean.StickListBean();
        stickListBean.cxGroupId = groupId;
        stickListBean.stickIndex = stickIndex;
        ApiManager.getApi().settingTopGroup(topGroupSettingBean).enqueue(new NetCallBack<TopGroupSettingBean>() {
            @Override
            protected void onSuccess(Call<TopGroupSettingBean> call, Response<TopGroupSettingBean> response) {
                if (response != null) {
                    UIUtils.showToast("设置成功");
                    ActivityUtils.finishActivity(SettingGroupPostionActivity.this);
                }
            }
        });
    }

    private void reSet() {
        mTop0.iv_click.setVisibility(View.GONE);
        mTop1.iv_click.setVisibility(View.GONE);
        mTop2.iv_click.setVisibility(View.GONE);
        mTop3.iv_click.setVisibility(View.GONE);
        mTop4.iv_click.setVisibility(View.GONE);
        mTop5.iv_click.setVisibility(View.GONE);
        mTop6.iv_click.setVisibility(View.GONE);
        mTop7.iv_click.setVisibility(View.GONE);
        mTop8.iv_click.setVisibility(View.GONE);
        mTop9.iv_click.setVisibility(View.GONE);
        mTop0.setSelected(false);
        mTop1.setSelected(false);
        mTop2.setSelected(false);
        mTop3.setSelected(false);
        mTop4.setSelected(false);
        mTop5.setSelected(false);
        mTop6.setSelected(false);
        mTop7.setSelected(false);
        mTop8.setSelected(false);
        mTop9.setSelected(false);
    }


}
